Syllabus, Last Week and Book
R Language - Part 3
TakeHome - MidTerm Project
Next Week - R Programming
Extended Syllabus PDF
PDF - (Pg. 127-133 and 150-155)
*due date: 07/12/2020 23:59
Create a Notebook
Practive - Data Types and Structures
Read
Write
Plot
*# Any number with (or without) a decimal point.
a <- 3
# Sub-class of the numeric class. The suffix L tells R to store.
a <- 3L
# TRUE or FALSE - Logical Operators. < , > , == , >= , <= , != ...
a <- 3<2
# Data type consists of letters or words. String. with quotes: " … "
a <- "3"
is.XXX() and class()
Vector : The simplest data structure in R
name <- "emir"
surname <- "toker"
print(c(name,surname)) # c means “combine”
Vectors indexed using two indices instead of one.
[ row, col ]
## [1] 1 2 3
## [,1] [,2] [,3]
## [1,] 1 2 3
## [,1] [,2] [,3]
## [1,] 1 4 7
## [2,] 2 5 8
## [3,] 3 6 9
## [,1] [,2] [,3]
## [1,] 1 2 3
## [2,] 4 5 6
## [3,] 7 8 9
## [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
## , , 1
##
## [,1] [,2] [,3]
## [1,] 1 5 9
## [2,] 2 6 10
## [3,] 3 7 11
## [4,] 4 8 12
##
## , , 2
##
## [,1] [,2] [,3]
## [1,] 13 17 21
## [2,] 14 18 22
## [3,] 15 19 23
## [4,] 16 20 24
[ row, col, level ]
matrix <- matrix(data=1:4,nrow=2,ncol=2)
vector <- c(T,F,T,T)
var <- "hello"
data_frame <- new_df2
list <- list(matrix,vector,var,data_frame)
class(list)
str(list)
dim(list)
length(list)
Read
Write
Plot
library(help="datasets")
list.files("/Users/emirtoker/Desktop/Dersler/Memurluk/Software_Tools_for_Earth_&_Environmental_Science/Software_Tools_R_Github/Presentation")
file.choose()
read.table(file = "18397_Cekmekoy_Omerli_15dk.txt")
read.table(file = "18397_Cekmekoy_Omerli_15dk.txt",
header=TRUE, sep=";")
read.table(file = "18397_Cekmekoy_Omerli_15dk.txt",
header=TRUE, sep=";", na.strings="-9999")
mydata_txt <- read.table(file = "18397_Cekmekoy_Omerli_15dk.txt",
header=TRUE,
sep=";",
na.strings="-9999")
str(mydata_txt)
mydata_csv <- read.csv(file="18397_Cekmekoy_Omerli.csv",
header=TRUE,
na.strings="-9999")
str(mydata_csv)
url <- "https://web.itu.edu.tr/tokerem/18397_Cekmekoy_Omerli_15dk.txt"
urldata_txt <- read.table(url,
header=TRUE,
sep=";",
na.strings="-9999")
Write .TXT and .CSV
write.table(x=urldata_txt,file="somenewfile.txt")
write.table(x=urldata_txt,file="somenewfile.txt",
sep=";",na="-9999",quote=FALSE,row.names=FALSE)
new_df2
write.table(x=new_df2,file="dffile.txt",
sep=";",na="-9999",quote=FALSE,row.names=FALSE)
write.table(x=new_df2,file="dffile.csv",
sep=";",na="-9999",quote=FALSE,row.names=FALSE)
foo <- c(1.1,2,3.5,3.9,4.2)
bar <- c(2,2.2,-1.3,0,0.2)
plot(foo,bar)
plot(foo,bar)
plot(foo,bar,type="l")
plot(foo,bar,type="b",main="My lovely plot",xlab="x axis label", ylab="location y")
plot(foo,bar,type="b",main="My lovely plot",xlab="",ylab="",col="red")
x <- 1:20
y <- c(-1.49,3.37,2.59,-2.78,-3.94,-0.92,6.43,8.51,3.41,-8.23,
-12.01,-6.58,2.87,14.12,9.63,-4.58,-14.78,-11.67,1.17,15.62)
plot(x,y,type="n",main="")
abline(h=c(-5,5),col="red",lty=2,lwd=2)
segments(x0=c(5,15),y0=c(-5,-5),x1=c(5,15),y1=c(5,5),col="red",lty=3,
lwd=2)
points(x[y>=5],y[y>=5],pch=4,col="darkmagenta",cex=2)
points(x[y<=-5],y[y<=-5],pch=3,col="darkgreen",cex=2)
points(x[(x>=5&x<=15)&(y>-5&y<5)],y[(x>=5&x<=15)&(y>-5&y<5)],pch=19,
col="blue")
points(x[(x<5|x>15)&(y>-5&y<5)],y[(x<5|x>15)&(y>-5&y<5)])
lines(x,y,lty=4)
arrows(x0=8,y0=14,x1=11,y1=2.5)
text(x=8,y=15,labels="sweet spot")
legend("bottomleft",
legend=c("overall process","sweet","standard",
"too big","too small","sweet y range","sweet x range"),
pch=c(NA,19,1,4,3,NA,NA),lty=c(4,NA,NA,NA,NA,2,3),
col=c("black","blue","black","darkmagenta","darkgreen","red","red"),
lwd=c(1,NA,NA,NA,NA,2,2),pt.cex=c(NA,1,1,2,2,NA,NA))
mydata_txt <- read.table(file = "18397_Cekmekoy_Omerli_15dk.txt",
header=TRUE,
sep=";",
na.strings="-9999")
mydata_txt
plot(mydata_txt$temp, type="l" )